package com.itheima.test5;

import java.io.UnsupportedEncodingException;
import java.util.Arrays;

/**
 * @Author:gy
 * @Date: 2025/08/28 15:05
 * @Description:
 */
public class Demo {
    public static void main(String[] args) throws UnsupportedEncodingException {
        //method1();
        //解码
       // byte [] bytes1 = {-23, -69, -111, -23, -87, -84, -25, -88, -117, -27, -70, -113, -27, -111, -104};
        //平台默认的是  utf-8
        byte [] bytes = {-70, -38, -62, -19, -77, -52, -48, -14, -44, -79};//gbk
        String s = new String(bytes,"GBK");
        System.out.println(s);

    }

    private static void method1() throws UnsupportedEncodingException {
        String s = "黑马程序员";
        //利用平台默认的字符集  UTF-8 将中文编辑成字节  编码
        byte[] bytes = s.getBytes();//[-23, -69, -111, -23, -87, -84, -25, -88, -117, -27, -70, -113, -27, -111, -104]
        System.out.println(Arrays.toString(bytes));
        byte[] gbks = s.getBytes("GBK");//[-70, -38, -62, -19, -77, -52, -48, -14, -44, -79]
        System.out.println(Arrays.toString(gbks));
    }
}
